﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="GroupServicePlanning.aspx.cs" Inherits="TireService.Web.View.ServiceView.GroupServicePlanning" %>


<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgContainer" alt="" src="~/Images/Medium/cubes_yellow.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblGroupServicePlanningHeader" runat="server" Text="Gruppe/Firma planlægning"></asp:Label></h3>
            </td>
        </tr>
    </table>
    <hr />

    
    <!-- Javascript of action dropdown list -->
    <script language="javascript" type="text/javascript">

        // Function that handles actions selected in dropdown list
        function ActionClicked() {

            // Get selected action from dropdownlist
            var id = ddlAction.GetValue();

            if (id != null && id != 0) {
                if (id == 1) {
                    
                }

                if (id == 2) {
                    
                }

            }
            else {
                alert('Ingen handling valgt');
            }
        }

        function ShowCreateServiceCarSchedule(containerid) {
            // Show create modal popup
            pcCreateServiceCarScheduleAllocation.Show();

            // Perform callback based on selected group servicecarschedule
            callbackCreateServiceCarScheduleAllocationPanel.PerformCallback(containerid);
        }

        function DeleteServiceCarSchedule(id) {

            var answer = confirm("Slet tildelt udkørsel fra gruppe/firma kørsel?")
            if (answer) {
                // Run callback function to delete record
                callDeleteServiceCarSchedule.PerformCallback(id);
            }
        }

        function AddServiceCarSchedule(ServiceCarScheduleId) {
         
            callbackAddServiceCarSchedule.PerformCallback(ServiceCarScheduleId);
        }

        function OnCallbackCreateServiceCarScheduleAllocationComplete() {

            // Nothing
        }

        // Function that runs when Serviceschedule has been removed from group serviceschedule
        function OnCallbackDeleteServiceCarScheduleComplete() {

            gvServiceCarSchedule.PerformCallback();
        }

        // Function that runs when Serviceschedule has been added to group serviceschedule
        function OnCallbackAddServiceCarScheduleAllocationComplete() {

            gvAvailableScheduleDates.PerformCallback();
            gvServiceCarSchedule.PerformCallback();
        }


        function CallBackError(s, e) {
            alert('Fejl opstod: ' + e.message);
        }



    </script>

    <dx:ASPxCallback ID="callDeleteServiceCarSchedule" ClientInstanceName="callDeleteServiceCarSchedule" runat="server" OnCallback="callDeleteServiceCarSchedule_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackDeleteServiceCarScheduleComplete" />
    </dx:ASPxCallback>

    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlAction" ClientInstanceName="ddlAction" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="true" Value="0" Text="-- Handling --" />
                        <%--<dx:ListEditItem Value="1" Text="Tilføj lagerpladser" />
                        <dx:ListEditItem Value="2" Text="Lagerflyt" />--%>
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { ActionClicked(); }" />
                </dx:ASPxButton>
            </td>
            <%--<td style="width:150px">
                <dx:ASPxComboBox ID="ddlExport" ClientInstanceName="ddlExport" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="True" Value="0" Text="Export pdf" />
                        <dx:ListEditItem Value="1" Text="Export xls" />
                        <dx:ListEditItem Value="2" Text="Export csv" />
                        <dx:ListEditItem Value="3" Text="Export rtf" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnExport" runat="server" Text="Exporter" Width="75px" >
                </dx:ASPxButton>
            </td>
            <td align="right">
                <asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:DropDownList ID="ddlView" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ddlView_SelectedIndexChanged">
                    <asp:ListItem Value="0">Ingen gruppering</asp:ListItem>
                </asp:DropDownList>
                &nbsp;
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>
            </td>--%>
        </tr>
    </table>          
    <hr />
    
    <dx:ASPxCheckBox ID="cbAllGroupServiceCarSchedule" ClientInstanceName="cbAllGroupServiceCarSchedule" Text="Vis kun Inaktive" runat="server">
        <ClientSideEvents CheckedChanged="function(s, e) { gvGroupServiceCarSchedule.PerformCallback(cbAllGroupServiceCarSchedule.GetChecked); }" />
    </dx:ASPxCheckBox>

    <dx:ASPxGridView ID="gvGroupServiceCarSchedule" runat="server" ClientInstanceName="gvGroupServiceCarSchedule" 
        KeyFieldName="GroupServiceCarScheduleId" Width="100%" AutoGenerateColumns="False" EnableCallBacks="True"
        OnCustomCallback="gvGroupServiceCarSchedule_CustomCallback"  
        OnRowInserting="gvGroupServiceCarSchedule_RowInserting"
        OnRowUpdating="gvGroupServiceCarSchedule_RowUpdating">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="True" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} gruppekørsler)" 
                Text="Side {0} af {1} ({2} gruppekørsler)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette denne gruppe kørsel?" GroupPanel="Træk kolonne hertil for at gruppere efter den" HeaderFilterShowAll="Vis alle" />
        <SettingsBehavior ConfirmDelete="True" AllowGroup="false" AllowDragDrop="false" AllowFocusedRow="true" />
        <ClientSideEvents FocusedRowChanged="function(s, e) {
            if (typeof(gvServiceCarSchedule) != 'undefined')
                gvServiceCarSchedule.PerformCallback(s.GetFocusedRowIndex());
        }" 
        />
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="0">
                <EditButton Visible="True" Text="Rediger" />
                <NewButton Visible="True" Text="Opret" />
            </dx:GridViewCommandColumn>
            <dx:GridViewDataColumn VisibleIndex="0">
                <DataItemTemplate>
                    <dx:ASPxButton ID="btnShowCreateServiceCarSchedule" runat="server" Text="Tildel udkørsler" ToolTip="Klik for at tildele udkørsler til gruppekørsel" AutoPostBack="false"
                        ClientSideEvents-Click='<%# "function(s, e) { ShowCreateServiceCarSchedule(" + Eval("ContainerId") + "); }" %>'>
                    </dx:ASPxButton>                                          
                </DataItemTemplate>
                <EditFormSettings Visible="False" />
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="GroupServiceCarScheduleId" VisibleIndex="2" Caption="GroupServiceCarSchedule Id">
                <EditFormSettings Visible="False" />
            </dx:GridViewDataColumn>
            <dx:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="0" Caption="Kundenr">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CustomerId">
                </PropertiesHyperLinkEdit>
                <EditFormSettings Visible="False" />
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataColumn FieldName="Description" VisibleIndex="1" Caption="Beskrivelse">
                <EditFormSettings Visible="True" />
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Address" VisibleIndex="2" Caption="Adresse">
                <EditFormSettings Visible="True" />
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ZipCode" VisibleIndex="3" Caption="Postnr">
                <EditFormSettings Visible="True" />
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="City" VisibleIndex="4" Caption="By">
                <EditFormSettings Visible="True" />
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="InfoOnCarParking" VisibleIndex="5" Visible="false" Caption="Detaljer for parkering">
                <EditFormSettings Visible="True" />
            </dx:GridViewDataColumn>
            <dx:GridViewDataComboBoxColumn Name="CountryDropdown" FieldName="CountryId" Caption="Land" VisibleIndex="6">
                <EditFormSettings VisibleIndex="5" />
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataComboBoxColumn Name="ContainerDropdown" FieldName="ContainerId" Caption="Lager" VisibleIndex="7">
                <EditFormSettings VisibleIndex="6" />
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataComboBoxColumn Name="CustomerDropdown" FieldName="CustomerId" Caption="Kunde" VisibleIndex="7">
                <EditFormSettings VisibleIndex="6" />
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataColumn FieldName="InActive" VisibleIndex="8" Caption="Deaktiveret">
                <EditFormSettings VisibleIndex="7" />
            </dx:GridViewDataColumn>
        </Columns>
        <SettingsEditing PopupEditFormModal="false" PopupEditFormHorizontalAlign="Center" PopupEditFormAllowResize="false" Mode="PopupEditForm" PopupEditFormWidth="600px" />
        <Templates>
            <EditForm>
                <div style="text-align: left; padding: 2px">
                    <h4>Gruppe / firma kørsel</h4>
                </div>
                <dx:ASPxGridViewTemplateReplacement ID="Editors" ReplacementType="EditFormEditors" runat="server">
                </dx:ASPxGridViewTemplateReplacement>
                <div style="text-align: left; padding: 2px">
                    <% if (gvGroupServiceCarSchedule.IsNewRowEditing) { %>
                        <!-- UDKOMMENTERET INDTIL LØSNING PÅ NEDENSTÅENDE ER FUNDET -->
                        <%--Vælg kunde:
                        <dx:ASPxComboBox ID="ddlCustomer" ClientInstanceName="ddlCustomer" IncrementalFilteringMode="StartsWith" 
                            DropDownWidth="320" DropDownStyle="DropDownList" runat="server" ValueField="CarId" TextFormatString="{1} {2}">
                            <ValidationSettings CausesValidation="true" ValidationGroup="SelectTaskType" RequiredField-IsRequired="true" RequiredField-ErrorText="Vælg kunde" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                <RequiredField IsRequired="True" ErrorText="V&#230;lg kunde"></RequiredField>
                            </ValidationSettings>
                            <Columns>
                                <dx:ListBoxColumn FieldName="ParentCompanyId" Caption="Hovedafdeling" Width="60px" />
                                <dx:ListBoxColumn FieldName="CompanyName" Caption="Firma" Width="80px" />
                                <dx:ListBoxColumn FieldName="CustomerId" Caption="Kundenr" Width="60px" />
                                <dx:ListBoxColumn FieldName="Name" Caption="Navn" Width="120px" />
                            </Columns>
                        </dx:ASPxComboBox>--%>

                    <% } %>
                </div>
                <div style="text-align: right; padding: 2px">
                    <dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server">
                    </dx:ASPxGridViewTemplateReplacement>
                    <dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server">
                    </dx:ASPxGridViewTemplateReplacement>
                </div>
            </EditForm>
        </Templates>            
    </dx:ASPxGridView>
    <hr />
    <dx:ASPxGridView ID="gvServiceCarSchedule" runat="server" ClientInstanceName="gvServiceCarSchedule" Width="100%" 
        KeyFieldName="ServiceCarScheduleId" AutoGenerateColumns="False" EnableCallBacks="True" 
        oncustomunboundcolumndata="gvServiceCarSchedule_CustomUnboundColumnData" OnCustomCallback="gvServiceCarSchedule_CustomCallback">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="True" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} kørselsdage)" 
                Text="Side {0} af {1} ({2} kørselsdage)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette denne kørselsdag?" />
        <SettingsBehavior ConfirmDelete="True" AllowGroup="false" AllowFocusedRow="false" AllowDragDrop="false" AllowSelectByRowClick="true" />
        <ClientSideEvents Init="function(s, e) {
	        s.PerformCallback(gvGroupServiceCarSchedule.GetFocusedRowIndex());
        }" />

        <Columns>
            <dx:GridViewDataColumn VisibleIndex="0">
                <DataItemTemplate>
                    <dx:ASPxButton ID="btnDeleteServiceCarGeoAreaAllocation" runat="server" Text="Slet" ToolTip="Klik for at slette tildelt område til gruppe / firma kørsel" AutoPostBack="false"
                        ClientSideEvents-Click='<%# "function(s, e) { DeleteServiceCarSchedule(" + Container.KeyValue + "); }" %>'>
                    </dx:ASPxButton>                                          
                </DataItemTemplate>
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ServiceCarId" VisibleIndex="1" Caption="Service bil">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ScheduleDate" VisibleIndex="2" Caption="Dato">
            </dx:GridViewDataColumn>
            <dx:GridViewDataTextColumn FieldName="TotalCapacity" VisibleIndex="3" UnboundType="String" Caption="Total kapacitet">
                <EditFormSettings Visible="False" />
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="FreeCapacity" VisibleIndex="4" UnboundType="String" Caption="Ledig kapacitet">
                <EditFormSettings Visible="False" />
            </dx:GridViewDataTextColumn>
            
        </Columns>                                            
    </dx:ASPxGridView>

    <dx:ASPxCallback ID="callbackAddServiceCarSchedule" ClientInstanceName="callbackAddServiceCarSchedule" runat="server" OnCallback="callbackAddServiceCarSchedule_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackAddServiceCarScheduleAllocationComplete" />
    </dx:ASPxCallback>

    <!-- Modalpopup: Assign ServiceCarSchedule to Group ServiceCarSchedule -->
    <dx:ASPxPopupControl ID="pcCreateServiceCarScheduleAllocation" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
        AllowDragging="True" ClientInstanceName="pcCreateServiceCarScheduleAllocation" Left="100" Top="100"
        CloseAction="CloseButton" Width="250px" HeaderText="Opret område allokering">
        <ClientSideEvents Closing="function(s, e) { gvServiceCarSchedule.PerformCallback() }" />
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
                <dx:ASPxCallbackPanel ID="callbackCreateServiceCarScheduleAllocationPanel" ClientInstanceName="callbackCreateServiceCarScheduleAllocationPanel" runat="server"
                    Width="450px" Height="100px" OnCallback="callbackCreateServiceCarScheduleAllocationPanel_Callback" RenderMode="Table">
                    <ClientSideEvents EndCallback="OnCallbackCreateServiceCarScheduleAllocationComplete" CallbackError="CallBackError" />
                    <PanelCollection>
                        <dx:PanelContent ID="PanelContent1" runat="server">
                            <dx:ASPxGridView ID="gvAvailableScheduleDates" runat="server" Caption="Kørselsdage" 
                                ClientInstanceName="gvAvailableScheduleDates" Width="100%" KeyFieldName="ServiceCarScheduleId" AutoGenerateColumns="False" EnableCallBacks="True"
                                OnCustomCallback="gvAvailableScheduleDates_CustomCallback">
                                <SettingsLoadingPanel Text="Henter&amp;hellip;" />
                                <Border BorderWidth="0px" />
                                <Settings ShowHeaderFilterButton="false" ShowGroupPanel="false" ShowFilterRow="false" ShowPreview="true" />
                                <SettingsPager AlwaysShowPager="False" PageSize="10" Position="Bottom">
                                    <Summary 
                                        AllPagesText="Sider: {0} - {1} ({2} udkørselsdage)" 
                                        Text="Side {0} af {1} ({2} udkørselsdage)" />
                                </SettingsPager>
                                <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" ConfirmDelete="True" AllowGroup="false" AllowDragDrop="false" />
                                <Columns>
                                    <dx:GridViewDataColumn FieldName="ServiceCarId" VisibleIndex="0" Caption="Service bil">
                                    </dx:GridViewDataColumn>
                                    <dx:GridViewDataTextColumn FieldName="ScheduleDate" Caption="Dato" VisibleIndex="1" />
                                    <dx:GridViewDataColumn VisibleIndex="2" Caption="Allokering">
                                        <DataItemTemplate>
                                            <dx:ASPxButton ID="btnAddServiceCarGeoAreaAllocation" runat="server" Text="Tilføj" ToolTip="Klik for at tildele område til gruppe/firma kørsel" AutoPostBack="false"
                                                ClientSideEvents-Click='<%# "function(s, e) { AddServiceCarSchedule(" + Container.KeyValue + "); }" %>'>
                                            </dx:ASPxButton>
                                        </DataItemTemplate>
                                    </dx:GridViewDataColumn>
                                    <dx:GridViewDataTextColumn FieldName="TotalCapacity" Caption="Total kapacitet" VisibleIndex="3" />
                                    <dx:GridViewDataTextColumn FieldName="FreeCapacity" Caption="Ledig kapacitet" VisibleIndex="4" />
                                </Columns>
                            </dx:ASPxGridView>

                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxCallbackPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>
                                
    <dx:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvServiceCarSchedule">
    </dx:ASPxGridViewExporter>

</asp:Content>
